﻿@using Smartstore.Web.Models.Catalog
@using Smartstore.Utilities

@model IQuantityInput

@functions{
    private string Value
    {
        get
        {
            string value = null;
            if (ViewData.Model != null)
            {
                value = Convert.ToString(ViewData.Model.EnteredQuantity);
            }
            return value;
        }
    }
}

@{
    var large = ViewData["large"].Convert<bool>();
    //var itemId = ViewData["itemId"].Convert<string>();
    // TODO: (mc) > (mh) finalize dropdown later in v3.1+
    var inputStyle = "spinner";
    //var inputStyle = Model.QuantityControlType;

    var attributes = new AttributeDictionary().Merge(ConvertUtility.ObjectToDictionary(ViewData["htmlAttributes"] ?? new object()));
}

<div class="qty-input">
    @if (inputStyle == "spinner")
    {
        <input asp-for="EnteredQuantity" 
               type="number" 
               attrs="@attributes"
               sm-control-size='@(large ? ControlSize.Large : ControlSize.Small)'
               sm-postfix="@Model.QuantityUnitName"
               sm-numberinput-style="Centered"
               data-step-interval="150"
               data-auto-select="false"
               data-auto-focus="false"
               min="@Model.MinOrderAmount"
               max="@Model.MaxOrderAmount"
               step="@Model.QuantityStep" />
    }
    else
    {
        <div sm-if="Model.AllowedQuantities != null && Model.AllowedQuantities.Count > 0" class="mf-dropdown" style="display: block">
            <button class="btn btn-warning btn-labeled icon-right btn-block" attr-class='(large, "btn-lg")'>
                <span data-bind="value">@Model.EnteredQuantity</span>
                <b><i class="fas fa-caret-down"></i></b>
            </button>
            <select asp-for="EnteredQuantity" asp-items="Model.AllowedQuantities" class="form-control qty-dropdown noskin"></select>
        </div>
    }
</div>